import {
	formateMoney,
	getImagePath
} from './utils/index.js';
import settings from './settings.js';
/**
 *  定义系统常量
 */
const Consts = {
	avatar: '/static/xjAvatar.png',
	//初始化
	initData: {
		//销量
		salesVolume: 10000,
		//播放量
		playsVolume: 9999,
		//关注量
		likesVolume: 999,
	},
	categoryType: {
		goods: 1,
		cms: 2
	},
	//页面地址
	pages: {
		
		categoryIndexPage: 'pages/category/index',
		searchIndexPage: 'pages/search/index',
		userIndexPage: 'pages/user/index',
		//商城页面
		orderDetailPage: 'xj_shop/order/detail',
		orderIndexPage: 'xj_shop/order/index',
		goodsDetailPage: 'xj_shop/goods/detail',
		goodsIndexPage: 'xj_shop/goods/index',
		goodsTenantPage: 'xj_shop/tenant/index',
		checkoutIndexPage: 'xj_shop/checkout/index',
		checkoutPayPage: 'xj_shop/checkout/pay',
		checkoutResultPage: 'xj_shop/checkout/result',
		//用户页面
		loginIndexPage: 'xj_user/login/index',
		addressIndexPage: 'xj_user/address/index',
		addressCreatePage: 'xj_user/address/create',
		addressUpdatePage: 'xj_user/address/update',
		configurationIndexPage: 'xj_user/configuration/index',
		agreementIndexPage: 'xj_user/agreement/index',
		billIndexPage: 'xj_user/bill/index',
		memberIndexPage: 'xj_user/member/index',
		//分销页面
		transitionIndexPage: 'xj_distribution/inder/transition',
		rulesIndexPage: 'xj_distribution/inder/rules',
		marketingApplyPage: 'xj_distribution/apply/marketing',
		createApplyPage: 'xj_distribution/apply/create',
		resultApplyPage: 'xj_distribution/apply/result',
		IndexDistributionPage: 'xj_distribution/index/index',
		goodsDistributionPage: 'xj_distribution/goods/index',
		orderDistributionPage: 'xj_distribution/order/index',
		customerDistributionPage: 'xj_distribution/customer/index',
		partnerDistributionPage: 'xj_distribution/partner/index',
		accountDistributionPage: 'xj_distribution/account/index',
		withdrawalAccountPage: 'xj_distribution/account/withdrawal',
		bankCardsAccountPage: 'xj_distribution/account/bankCards',
		createAccountPage: 'xj_distribution/account/create',
		resultAccountPage: 'xj_distribution/account/result',
		analysisDistributionPage: 'xj_distribution/analysis/index',
		//门店页面
		indexStorePage: 'xj_tenant/index/index',
		indexAddressPage: 'xj_tenant/address/index',
		updateStorePage: 'xj_tenant/index/update',
		indexOrderPage: 'xj_tenant/order/index',
		manualVerificationPage: 'xj_tenant/verification/manual',
		scanVerificationPage: 'xj_tenant/verification/scan',
	},
	//订单分类
	OrderCategory: [{
		id: 2,
		name: '待付款',
		value: 'payment'
	}, {
		id: 3,
		name: '待发货',
		value: 'deliver'
	}, {
		id: 4,
		name: '待收货',
		value: 'received'
	}, {
		id: 5,
		name: '待退款',
		value: 'refund'
	}],
	//优惠券分类
	couponCategory: [{
		id: 1,
		name: '未使用'
	}, {
		id: 2,
		name: '已使用'
	}, {
		id: 3,
		name: '已过期'
	}],
	//所有的配送方式
	shippingMethods: [{
			id: 0,
			name: '无需快递'
		},
		{
			id: 1,
			name: '快递到家'
		},
		{
			id: 2,
			name: '同城配送'
		},
		{
			id: 3,
			name: '门店自提'
		}
	],
};
/**
 * 常量格式化函数
 *
 * @param Formatter
 * @param id
 * @returns {*}
 * @constructor
 */
const Formatter = function(Formatter, id) {
	let item = Formatter.filter(item => {
		if (item.id === id) {
			return item;
		}
	});
	return item && item.length ? item[0].name : '';
};

export default {
	//
	data() {
		return {
			...Consts,
		};
	},
	//
	methods: {
		//初始化滚动组件高度
		initMescrollHeight(vueComponent, statusBar) {
			// #ifdef H5
			let wHeight = window.innerHeight;
			let tHeight = vueComponent.$el.getBoundingClientRect().top;
			
			if (wHeight >= tHeight) {
				if (statusBar) {
					return wHeight - tHeight - statusBar;
				} else {
					return wHeight - tHeight;
				}
			}
			// #endif
			// else {
			// 	//处理层叠问题
			// 	return wHeight - (tHeight - wHeight);
			// }
			return '';
		},
		//
		toTargetPage(page, params) {
		  let toTargetPage = this.targetPage;
		  if (!toTargetPage) {
		    toTargetPage = page;
		  }
		  this.$app.navTo(toTargetPage, params);
		}
		
	},
	filters: {
		YesNo: function(id) {
			return id ? '是' : '否';
		},
		Money: function(val) {
			return formateMoney(val / 100);
		},
		ImageSrc: function(image) {
			return settings.api + getImagePath(image);
		},
	}
};
